﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Visifire.Charts;

namespace CPPEI.Coolzon.UI.DataPartLib
{
    public partial class DataChartBase
    {
        protected void SetLegends(LegendCollection legends)
        {
            if (legends == null || legends.Count == 0)
            {
                Legend legend = new Legend();
                legend.Enabled = LegendEnabled;
                legend.Background = LegendBackground==null? null : LegendBackground.Brush;
                legend.HorizontalAlignment = LegendHorizontalAlignment;
                legend.VerticalAlignment = LegendVerticalAlignment;
                legend.FontFamily = LegendFontFamily;
                legend.FontWeight = LegendFontWeight;
                legend.FontSize = LegendFontSize;
                legend.FontColor = LegendFontColor==null? null : LegendFontColor.Brush;
                legend.DockInsidePlotArea = LegendDockInsidePlotArea;
                legend.EntryMargin = LegendEntryMargin;
                legend.LabelMargin = LegendLabelMargin;
                legend.LightingEnabled = LegendLightingEnabled;
                legend.ShadowEnabled = LegendShadowEnabled;
                legend.OverridesDefaultStyle = false;
                legend.BorderThickness = LegendBorderThickness;
                legend.BorderColor = LegendBorderColor==null? null : LegendBorderColor.Brush;
                if (LegendMarkerSize != null)
                    legend.MarkerSize = LegendMarkerSize.Value;

                legends.Add(legend);
                return;
            }
            foreach(var legend in legends)
            {
                legend.Enabled = LegendEnabled;
                legend.Background = LegendBackground== null? null : LegendBackground.Brush;
                legend.HorizontalAlignment = LegendHorizontalAlignment;
                legend.VerticalAlignment = LegendVerticalAlignment;
                legend.FontFamily = LegendFontFamily;
                legend.FontWeight = LegendFontWeight;
                legend.FontSize = LegendFontSize;
                legend.FontColor = LegendFontColor==null? null : LegendFontColor.Brush;
                legend.DockInsidePlotArea = LegendDockInsidePlotArea;
                legend.EntryMargin = LegendEntryMargin;
                legend.LabelMargin = LegendLabelMargin;
                legend.LightingEnabled = LegendLightingEnabled;
                legend.ShadowEnabled = LegendShadowEnabled;
                legend.OverridesDefaultStyle = false;
                legend.BorderThickness = LegendBorderThickness;
                legend.BorderColor = LegendBorderColor==null? null : LegendBorderColor.Brush;
                if (LegendMarkerSize != null)
                    legend.MarkerSize = LegendMarkerSize.Value;
            }
        }

        private Thickness legendBorderThickness;
        private BrushEx legendBorderColor;
        private bool legendEnabled;
        private BrushEx legendBackground;
        private HorizontalAlignment legendHorizontalAlignment;
        private VerticalAlignment legendVerticalAlignment;
        private FontFamily legendFontFamily;
        private FontWeight legendFontWeight;
        private int legendFontSize;
        private BrushEx legendFontColor;
        private bool legendDockInsidePlotArea;
        private double legendEntryMargin;
        private double legendLabelMargin;
        private bool legendLightingEnabled;
        private bool legendShadowEnabled;
        private double? legendMarkerSize;

        [Category("图例")]
        [DisplayName("图例是否可用")]
        [Description("LegendEnabled")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendEnabled", "是否可用")]
        public bool LegendEnabled
        {
            get
            {
                return legendEnabled;
            }

            set
            {
                legendEnabled = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例背景颜色")]
        [Description("LegendBackground")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendBackground", "背景颜色")]
        public BrushEx LegendBackground
        {
            get
            {
                return legendBackground;
            }

            set
            {
                legendBackground = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例水平对齐")]
        [Description("LegendHorizontalAlignment")]
        [Editor(typeof(UI.XProperty.Editors.XHorizontalAlignmentEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendHorizontalAlignment", "水平对齐")]
        public HorizontalAlignment LegendHorizontalAlignment
        {
            get
            {
                return legendHorizontalAlignment;
            }

            set
            {
                legendHorizontalAlignment = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例垂直对齐")]
        [Description("LegendVerticalAlignment")]
        [Editor(typeof(UI.XProperty.Editors.XVerticalAlignmentEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendVerticalAlignment", "垂直对齐")]
        public VerticalAlignment LegendVerticalAlignment
        {
            get
            {
                return legendVerticalAlignment;
            }

            set
            {
                legendVerticalAlignment = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例字体")]
        [Description("LegendFontFamily")]
        [Editor(typeof(UI.XProperty.Editors.XFontFamilyEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendFontFamily", "字体")]
        public FontFamily LegendFontFamily
        {
            get
            {
                return legendFontFamily;
            }

            set
            {
                legendFontFamily = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例字体粗细")]
        [Description("LegendFontWeight")]
        [Editor(typeof(UI.XProperty.Editors.XFontWeightEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendFontWeight", "字体粗细")]
        public FontWeight LegendFontWeight
        {
            get
            {
                return legendFontWeight;
            }

            set
            {
                legendFontWeight = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例字体大小")]
        [Description("LegendFontSize")]
        [Editor(typeof(UI.XProperty.Editors.XIntEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendFontSize", "字体大小")]
        public int LegendFontSize
        {
            get
            {
                return legendFontSize;
            }

            set
            {
                legendFontSize = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例字体颜色")]
        [Description("LegendFontColor")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendFontColor", "字体颜色")]
        public BrushEx LegendFontColor
        {
            get
            {
                return legendFontColor;
            }

            set
            {
                legendFontColor = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例是否显示在数据区域内")]
        [Description("LegendDockInsidePlotArea")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendDockInsidePlotArea", "是否显示在数据区域内")]
        public bool LegendDockInsidePlotArea
        {
            get
            {
                return legendDockInsidePlotArea;
            }

            set
            {
                legendDockInsidePlotArea = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例条目间距")]
        [Description("LegendEntryMargin")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendEntryMargin", "条目间距")]
        public double LegendEntryMargin
        {
            get
            {
                return legendEntryMargin;
            }

            set
            {
                legendEntryMargin = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例标签间距")]
        [Description("LegendLabelMargin")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendLabelMargin", "标签间距")]
        public double LegendLabelMargin
        {
            get
            {
                return legendLabelMargin;
            }

            set
            {
                legendLabelMargin = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例是否高亮")]
        [Description("LegendLightingEnabled")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendLightingEnabled", "是否高亮")]
        public bool LegendLightingEnabled
        {
            get
            {
                return legendLightingEnabled;
            }

            set
            {
                legendLightingEnabled = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例是否显示阴影")]
        [Description("LegendShadowEnabled")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendShadowEnabled", "是否显示阴影")]
        public bool LegendShadowEnabled
        {
            get
            {
                return legendShadowEnabled;
            }

            set
            {
                legendShadowEnabled = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例图例大小")]
        [Description("LegendMarkerSize")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendMarkerSize", "图例大小")]
        public double? LegendMarkerSize
        {
            get
            {
                return legendMarkerSize;
            }

            set
            {
                legendMarkerSize = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例图例边框大小")]
        [Description("LegendBorderThickness")]
        [Editor(typeof(UI.XProperty.Editors.XThicknessEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendBorderThickness", "图例边框大小")]
        public Thickness LegendBorderThickness
        {
            get
            {
                return legendBorderThickness;
            }

            set
            {
                legendBorderThickness = value;
                Refresh();
            }
        }

        [Category("图例")]
        [DisplayName("图例图例边框颜色")]
        [Description("LegendBorderColor")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "LegendBorderColor", "图例边框颜色")]
        public BrushEx LegendBorderColor
        {
            get
            {
                return legendBorderColor;
            }

            set
            {
                legendBorderColor = value;
                Refresh();
            }
        }
    }
}
